package com.wc.算法基础课.A第一讲基础算法.多路归并.序列;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/3/9 11:04
 * @description https://www.acwing.com/problem/content/148/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 2010;
    static int[] a = new int[N], b = new int[N], c = new int[N];
    static int m, n, t;

    public static void main(String[] args) {
        t = sc.nextInt();
        while (t-- > 0) {
            m = sc.nextInt();
            n = sc.nextInt();
            for (int i = 1; i <= n; i++) a[i] = sc.nextInt();
            Arrays.sort(a, 1, n + 1);
            for (int i = 1; i < m; i++) {
                for (int j = 1; j <= n; j++) b[j] = sc.nextInt();
                merge();
            }
            for (int i = 1; i <= n; i++) out.print(a[i] + " ");
            out.println();
        }
        out.flush();
    }

    static void merge() {
        PriorityQueue<Pair> q = new PriorityQueue<>();
        for (int i = 1; i <= n; i++) q.add(new Pair(a[1] + b[i], 1));
        for (int i = 1; i <= n; i++) {
            Pair t = q.poll();
            c[i] = t.x;
            q.add(new Pair(c[i] - a[t.y] + a[t.y + 1], t.y + 1));
        }
        for (int i = 1; i <= n; i++) a[i] = c[i];
    }

    static class Pair implements Comparable<Pair> {
        int x, y;

        Pair(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public int compareTo(Pair o) {
            if (x == o.x) {
                return y - o.y;
            }
            return x - o.x;
        }
    }

}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}